package com.zhangsun.yueBoot.framework.aop;

import com.zhangsun.yueBoot.commons.base.bean.ResponseResult;
import com.zhangsun.yueBoot.commons.logger.MyLoggerFactory;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 异常统一处理的切面，暂未使用，用exceptionHandler实现
 * @see com.zhangsun.yueBoot.framework.expection.GlobalExceptionHandler
 */
// @Component
// @Aspect
@Deprecated
public class ExceptionAspect {

    private MyLoggerFactory logger;

    @Autowired
    public ExceptionAspect(MyLoggerFactory logger) {
        this.logger = logger;
    }

    @Pointcut("execution(* com.zhangsun.yueBoot.admin.*.controller..*(..))")//此处基于自身项目的路径做具体的设置
    public void pointCut(){}

    @Around("pointCut()")
    public Object handleControllerMethod(ProceedingJoinPoint proceedingJoinPoint) {
        Object responseResult;
        try {
            responseResult = proceedingJoinPoint.proceed(proceedingJoinPoint.getArgs());
        } catch (Throwable throwable) {
            logger.error(throwable);
            responseResult = ResponseResult.error("500", throwable.getMessage());
        }

        return responseResult;
    }

}
